import { UserProfilesAPI } from "../../request/api";
export default {
  namespaced: true,
  state: {
    //购物车数量
    cartTotal: 0,
    //用户信息
    userInfo: {
      //昵称
      nickName: "Daniao",
      coin: "100",
      headImg: require("../../assets/img/userImg.f8bbec5e.png"),
    },
  },
  getters: {},
  mutations: {
    //修改用户信息
    updateUserInfo(state, payload) {
      state.cartTotal = payload.cartTotal;
      state.userInfo = payload.userInfo;
    },
    //初始化用户信息
    initUserInfo(state) {
      state.cartTotal = 0;
      state.userInfo = {
        //昵称
        nickName: "Daniao",
        coin: "100",
        headImg: require("../../assets/img/userImg.f8bbec5e.png"),
      };
    },
  },
  actions: {
    //发起请求 得到用户信息，更新到vuex中
    async asyncChangeUserInfo({ commit }) {
      let res = await UserProfilesAPI();
      // console.log("asyncChangeUserInfo", res);
      commit("updateUserInfo", res.data);
    },
  },
};
